extends CanvasLayer

@onready var coin_num: Label = $Right/CoinNum
@onready var level_num: Label = $Right/LevelNum
@onready var load: Button = $Left/Load
@onready var last_save: Label = $Left/LastSave
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var new: Button = $Left/New


func _ready() -> void:
	hide()


func show_game_over_screen() -> void:
	var file := FileAccess.open(Game.SAVE_PATH, FileAccess.READ)
	if not file:
		load.disabled = true
		last_save.hide()
	else:
		load.disabled = false
		load.show()
		var json := file.get_as_text()
		var data := JSON.parse_string(json) as Dictionary
		var save := data.save_time as String
		last_save.text = "Last Save: " + save
	
	coin_num.text = "Coin Collected: " + str(GlobalGameData.player_coin)
	level_num.text = "Highest Level: " + str(GlobalGameData.highest_level)
	
	animation_player.play("show")
	
	new.grab_focus()


func _on_new_pressed() -> void:
	Game.new_game()


func _on_load_pressed() -> void:
	Game.load_game()


func _on_quit_pressed() -> void:
	get_tree().quit()
